#include "StateManager.h"
namespace Putin{

StateManager::StateManager(void)
{
}

StateManager::~StateManager(void)
{
}

void StateManager::start(State* state)
{
	changeState(state);
}

void StateManager::changeState(State *state)
{
	if(!mStates.empty())
	{
		mStates.back()->exit();
		mStates.pop_back();
	}
	mStates.push_back(state);
	mStates.back()->enter();
}

void StateManager::pushState(State *state)
{
	if(!mStates.empty())
	{
		mStates.back()->pause(); // Pause the current state
	}

	mStates.push_back(state);
	mStates.back()->enter();
}

void StateManager::popState()
{
	if(!mStates.empty())
	{
		mStates.empty();
		mStates.pop_back();
	}

	if(!mStates.empty())
	{
		mStates.back()->resume();
	}
}

void StateManager::update()
{
	if(!mStates.empty())
	{
		mStates.back()->update();
	}
}

}